/*
 * This file is part of quickReminder, a software for gamers
 *
 * Copyright (C) 2006-2008 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Net;
using System.IO;

namespace LucasCode
{
    public abstract class MatchHelpers
    {
        public static string getIDFromLink(string link)
        {
            return Regex.Match(link, @"/(\d+)/*$", RegexOptions.Compiled).Groups[1].Value;
        }


        public static string GetHTML(string URL)
        {
            return GetHTML(URL, String.Empty);
        }

        public static string GetHTML(string URL, string cook)
        {
            return GetHTML(URL, new Cookie("COOKIE", cook, "/", ".esl.eu"));
        }

        public static string GetHTML(string URL, Cookie cook)
        {
            string HTML = String.Empty;
            HttpWebRequest request;
            HttpWebResponse response;
            StreamReader answer = null;
            request = (HttpWebRequest)WebRequest.Create(URL);
            request.Timeout = 30000;
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(cook);
            //get response

            try
            {
                response = (HttpWebResponse)request.GetResponse();
                answer = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                HTML = answer.ReadToEnd();
            }
            catch (WebException ex)
            {
                throw;
            }
            finally
            {
                if (answer != null)
                    answer.Close();
            }
            return HTML;
        }
    }
}
